package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.admin.ReportService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;

@RestController
@Slf4j
@RequestMapping
@Api(tags = "报表管理")
public class ReportController {
    @Autowired
    private ReportService reportService;
    @GetMapping("/admin/report/turnoverStatistics")
    @ApiOperation("营业额统计")
    public Result<TurnoverReportVO> report(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                           @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        log.info("营业额统计");
        TurnoverReportVO vo=reportService.report(begin,end);
        return Result.success(vo);
    }
    @ApiOperation("订单统计")
    @GetMapping("/admin/report/ordersStatistics")
    public Result<OrderReportVO> orderReport(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                             @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        log.info("订单统计");
        OrderReportVO vo=reportService.orderReport(begin,end);
        return Result.success(vo);
    }
    @ApiOperation("销量统计")
    @GetMapping("/admin/report/top10")
    public Result<SalesTop10ReportVO> top10(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        log.info("销量统计");
        SalesTop10ReportVO vo=reportService.top10(begin,end);
        return Result.success(vo);
    }
    @ApiOperation("用户统计")
    @GetMapping("/admin/report/userStatistics")
    public Result<UserReportVO> userReport(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                           @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
    log.info("用户统计");
    UserReportVO vo=reportService.userReport(begin,end);
    return Result.success(vo);
    }
    @ApiOperation("导出运营数据报表")
    @GetMapping("/admin/report/export")
    public void export(HttpServletResponse response) throws IOException {
        log.info("导出运营数据报表");
        reportService.export(response);
    }
}
